﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section styles{
    <style>
        xm-select * {
            font-size: 12px;
        }
    </style>

}
<div class="ok-body">
    <form class="layui-form model-form">
        @if (!string.IsNullOrEmpty(Model.Parentcode))
        {
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">字典类型:</label>
                <div class="layui-input-block">
                    <div id="selectdict"></div>
                </div>
            </div>
        }

        <div class="layui-form-item">

            <label class="layui-form-label layui-form-required">名称:</label>
            <div class="layui-input-block">
                <input type="text" id="Dname" name="Dname" lay-verify="required|Dname" placeholder="一般不要超过10个汉字" lay-vertype="tips"
                       autocomplete="off" class="layui-input" value="@Model.Dname" />
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">代码:</label>
            <div class="layui-input-block">
                <input type="text" id="Dcode" name="Dcode" required="" lay-verify="required" placeholder=" 字典能唯一标识" lay-vertype="tips"
                       autocomplete="off" class="layui-input @(!string.IsNullOrEmpty(Model.Dcode)?"readonly-b":"")" @(!string.IsNullOrEmpty(Model.Dcode) ? "readonly" : "") value="@Model.Dcode" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">排序:</label>
            <div class="layui-input-block">
                <input type="number" id="Dseq" name="Dseq" required="" placeholder="一般用于调整显示顺序" lay-vertype="tips"
                       autocomplete="off" class="layui-input" value="@Model.Dseq" />
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">是否可见:</label>
            <div class="layui-input-block">
                <input type="radio" name="isenable" value="0" title="禁用" @(!Model.Isenable ? "checked" : "") />
                <input type="radio" name="isenable" value="1" title="可用" @(Model.Isenable ? "checked" : "") />
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">自定义类型:</label>
            <div class="layui-input-block">
                <input type="text" id="Dictype" name="Dictype" placeholder="一般用于自定义类型"
                       autocomplete="off" class="layui-input" value="@Model.Dictype" />
            </div>

        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                备注
            </label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="请输入备注" class="layui-textarea">@Model.Remark</textarea>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-color" lay-filter="add" lay-submit="">
                保存
            </button>
            <button class="layui-btn layui-btn-cancel" type="button" onclick="closeDialog()">取消</button>
        </div>
        <input type="hidden" name="id" value="@Model.Id" />
        <input type="hidden" name="Parentcode" value="" />
    </form>

</div>

@section scripts{
    <script>

        layui.config({
            base: '/Content/lib/modules/'
        }).extend({
            xmSelect: 'xm-select'
        }).use(['form', 'okLayer', 'okUtils', 'xmSelect'], function () {
            $ = layui.jquery;
            var form = layui.form;
            var okLayer = layui.okLayer;
            var okUtils = layui.okUtils;
            var xmSelect = layui.xmSelect;
            okLoading.close();
        //自定义验证规则
        form.verify({
            Dname: function (value) {
                if (lscom.strlength(value) > 30) {
                    return '超过30个字符限制';
                }
            }
        });
        if ('@Model.Parentcode' != "") {
                var selectdict = xmSelect.render({
                el: '#selectdict',
                radio: true,
                clickClose: true,
                filterable: true,
                size: 'mini',
                theme:
                {
                color: '#0081ff',
                },
                model:
                {
                icon: 'hidden',
                    label:
                {
                type: 'text'
                    }
                },
                data: []
                });
                $.ajax({
                        type: 'get',
                url: '/Systems/Dictionary/GetDictionaryCondition',
                dataType: 'json',
                success: function(res) {
                                selectdict.update({
                                data: res.data,
                        autoRow: true,
                    });
                                selectdict.setValue(["@Model.Parentcode"]);
                            }
                        });


        }



        //监听提交
        form.on('submit(add)',
            function (data) {
                if ('@Model.Parentcode' != "") {
                    $("input[name='Parentcode']").val(selectdict.getValue('value'));
                }
               lscom.saveformdata("/Systems/Dictionary/SaveDictionary", $(data.form).serialize(), okUtils, okLayer);
              
                return false;
            });

    });</script>
}

